<template>
	<view>
		<view class="top">
			<image src="../static/hua.png" mode=""></image>
			提交评价或建议，鼓励商家做的更好~
		</view>
		<view class="content">
			<view class="tit">
				您对商家/商品满意吗？
			</view>
			<view class="shop">
				<image :src="orderinfo.productLogo" mode="aspectFill"></image>
				<view class="texts">
					<view class="">{{orderinfo.shopName}}</view>
					<view class="tts">{{orderinfo.productName}}({{orderinfo.productCount}}份)
						<span>￥{{orderinfo.orderAmount}}</span> <span
							class="s2">￥{{orderinfo.productPriceOldBegin}}-{{orderinfo.productPriceOldEnd}}</span>
					</view>
				</view>
			</view>
			<view class="pj">
				评价 <uni-rate style="margin-left: 24rpx;" size="18" v-model="params.rating"
					active-color="#000"></uni-rate>
			</view>
			<view class="tips">
				<view class="its"
				:class="item.default?'itsact':'its'"
				@click="change(item)"
				v-for="(item,index) in yylist" :key="index">
					{{item.dictLabel}}
				</view>
			</view>
			<view class="tests">
				<textarea placeholder-class="textarea" placeholder="口味如何，对商品和服务等满意吗？" 
				v-model="params.content" maxlength="200">
				</textarea>
				<view class="testsabs">
					{{params.content.length}}/200
				</view>
			</view>
			<view class="upload">
				<imageUpload
				:upWith="140" :upHeight="140"
				:imgList="imageList" :maxCount="3" @change="imgFn"></imageUpload>
			</view>
		</view>
		<view class="footerbtn">
			<view class="cont">
				<view class="btn b1" @click="godetails">
					提交
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	import {
		ordersInfo,
		getdict,
		commentOrder
	} from '@/common/http.api.js';
	export default {
		data() {
			return {
				value: '',
				yylist: [],
				orderinfo: {},
				imageList:[],
				params: {
					orderId : '',
					rating: 0,
					tag:'',
					content:'',
					img:null
				}
			};
		},
		onLoad(option) {
			this.params.orderId = option.id
			getdict('self_comment_tag').then(res => {
				this.yylist = res.data
			})
			ordersInfo({
				id: option.id
			}).then(res => {
				res.data.productCategory = res.data.productCategory.split(',')
				this.orderinfo = res.data
				this.shopinfo = res.data.shop
			})
		},
		methods: {
			//点击标签
			change(item){
				item.default=!item.default
			},
			//图片上传
			imgFn(e){
				this.imageList = e
				console.log(e);
				let ulist = e.map(item=>{return item.url})
				this.params.img = ulist.join(',')
			},
			godetails() {
				let list = this.yylist.filter(item=>{return item.default})
				this.params.tag = list.map(item=>{return item.dictLabel}).join(',')
				if(this.params.rating == 0){
					uni.showToast({
						title:'请对当前商家或商品打分',
						icon:'none'
					})
					return
				}
				if(this.params.tag == ''){
					uni.showToast({
						title:'请至少选择一个标签',
						icon:'none'
					})
					return
				}
				if(this.params.content == ''){
					uni.showToast({
						title:'请输入评价内容',
						icon:'none'
					})
					return
				}
				console.log(this.params);
				commentOrder(this.params).then(res=>{
					setTimeout(()=>{
						uni.redirectTo({
							url:'/mainpage/evaluateyes'
						})
					},500)
				})
				
			}
		}
	}
</script>

<style lang="scss" scoped>
	page {
		background: #FBFBFB;
	}

	.top {
		width: 750rpx;
		height: 68rpx;
		background: #FFEFD9;
		border-radius: 0rpx 0rpx 0rpx 0rpx;
		font-family: PingFang SC, PingFang SC;
		font-weight: 500;
		font-size: 22rpx;
		color: #CE7034;
		display: flex;
		align-items: center;
		padding: 0rpx 20rpx;
		box-sizing: border-box;

		image {
			width: 50rpx;
			height: 50rpx;
			margin-right: 10rpx;
		}
	}

	.content {
		width: 710rpx;
		background: #FFFFFF;
		border-radius: 20rpx 20rpx 20rpx 20rpx;
		margin: 20rpx auto;
		padding: 30rpx 20rpx;
		box-sizing: border-box;

		.tit {
			font-family: PingFang SC, PingFang SC;
			font-weight: bold;
			font-size: 30rpx;
			color: #000000;
			border-bottom: 1px solid #eee;
			padding-bottom: 10rpx;
		}

		.shop {
			display: flex;
			margin: 14rpx auto 0rpx;

			image {
				width: 80rpx;
				height: 80rpx;
				border-radius: 10rpx;
			}

			.texts {
				font-family: PingFang SC, PingFang SC;
				font-weight: 500;
				font-size: 28rpx;
				color: #000000;
				margin-left: 12rpx;

				.tts {
					margin-top: 10rpx;
					font-family: PingFang SC, PingFang SC;
					font-weight: 500;
					font-size: 24rpx;
					color: #000000;

					span {
						font-family: 'FINE';
						margin-left: 6rpx;
					}

					.s2 {
						color: #979797;
						text-decoration-line: line-through;
					}
				}
			}
		}

		.pj {
			display: flex;
			align-items: center;
			font-family: PingFang SC, PingFang SC;
			font-weight: 500;
			font-size: 28rpx;
			color: #000000;
			margin: 30rpx auto;
		}

		.tips {
			display: flex;
			font-family: PingFang SC, PingFang SC;
			font-weight: 500;

			.its {
				height: 48rpx;
				background: #F9F9F9;
				padding: 0rpx 15rpx;
				font-size: 24rpx;
				color: #B4B4B4;
				line-height: 48rpx;
				margin-right: 20rpx;
			}

			.itsact {
				background: #036029;
				color: #fff;
			}
		}

		.tests {
			width: 670rpx;
			height: 280rpx;
			background: #FBFBFB;
			border-radius: 0rpx 0rpx 0rpx 0rpx;
			margin: 30rpx auto 0rpx;
			position: relative;

			.textarea {
				font-weight: 400;
				color: #D1D1D6;
			}

			textarea {
				width: 100%;
				font-family: PingFang SC, PingFang SC;
				font-weight: 400;
				font-size: 28rpx;
				color: #000000;
				padding: 20rpx;
				box-sizing: border-box;
				height: 280rpx;
				border-radius: 10rpx;
			}

			.testsabs {
				position: absolute;
				bottom: 10rpx;
				right: 10rpx;
				font-size: 24rpx;
				color: #D1D1D6;
			}
		}

		.upload {
			width: 670rpx;
			background: #FBFBFB;
			padding: 20rpx;
			box-sizing: border-box;
			display: flex;

			.imglist {
				width: 140rpx;
				height: 140rpx;
				margin-right: 20rpx;
				position: relative;

				image {
					width: 140rpx;
					height: 140rpx;
					border-radius: 8rpx;
				}

				.icons {
					position: absolute;
					right: -16rpx;
					top: -16rpx;
				}

			}

			.add {
				display: flex;
				justify-content: center;
				align-items: center;
				font-family: PingFang SC, PingFang SC;
				font-weight: 500;
				font-size: 24rpx;
				color: #979797;
				border: 1px solid #eee;
				width: 140rpx;
				height: 140rpx;
				border-radius: 8rpx;
				text-align: center;

				image {
					width: 48rpx;
					height: 48rpx;
				}
			}
		}
	}

	.footerbtn {
		width: 750rpx;
		height: 120rpx;
		background: #FFFFFF;
		border-top: 1px solid #eee;
		position: fixed;
		bottom: 0%;
		padding-bottom: constant(safe-area-inset-bottom);
		padding-bottom: env(safe-area-inset-bottom);

		.cont {
			display: flex;
			padding: 10rpx 20rpx;
			height: 120rpx;
			font-family: PingFang SC, PingFang SC;
			font-weight: 500;
			font-size: 32rpx;
			align-items: center;
			justify-content: center;

			.btn {
				width: 670rpx;
				height: 100rpx;
				background: #000000;
				border-radius: 8rpx 8rpx 8rpx 8rpx;
				font-family: PingFang SC, PingFang SC;
				font-weight: 500;
				font-size: 32rpx;
				line-height: 100rpx;
				text-align: center;
				color: #fff;
			}
		}
	}
</style>